import { defineStore } from 'pinia'

export const useKeepAliveStore = defineStore('keepAlive', {
    state: () => {
        return {
            keepAliveComponentsName: [] // 需要缓存的组件名称
        }
    },
    actions: {
        setKeepAliveComponentsName(nameArr) {
            this.keepAliveComponentsName = nameArr
        },
        addKeepAliveComponentsName(name) {
            this.keepAliveComponentsName.push(name)
        },
        delKeepAliveComponentsName(name) {
            const key = this.keepAliveComponentsName.indexOf(name)
            if (key !== -1) {
                this.keepAliveComponentsName.splice(key, 1)
                console.log(this.keepAliveComponentsName)
            }
        }
    }
})
